<?php
namespace Admin\Controller;

use Think\Controller;

class JpushController extends ComController
{
    
    /*
     * 后台极光推送
     * title 标题
     * content 描述
     * bid   书ID;h5链接
     * typeid  1,book;2,h5;3,空;4,task 
     */
    public function jpush() {
        $data = I('post.');
        if(empty($data['title']) || empty($data['content']) || empty($data['bid'])){
            $this->error('数据不能为空');
        }
       $type = $data['type']?$data['type']:'book';
       $type_id = $data['typeid']?$data['typeid']:'1';//1代表跳转到书简介
       $result =  $this->jpusher($data['title'],$data['content'],['bid'=>$data['bid'],'type'=>$type,'type_id'=>$type_id]);
       if($result){
           $data['add_time'] = date('Y-m-d',time());
           D('Jpush')->add($data);
           $this->success('发送成功', U('book/book_list'));
       }
        
    }
    
    public function index() {
        
        $page = I('get.page',1);
        $pre_page = I('get.pre_page',30);
        $b = M('jpush');
        $w = array();
        $count = $b->where($w)->count();
        $Page = new \Think\Page($count,$pre_page);
        $show = $Page->show();
        $jpush = $b->where($w)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('count', $count);
        $this->assign('jpush', $jpush);
        $this->assign('page', $show);
        $this->display();
    }
    
    public function del_reply_keywords() {
        $jpush = "jpush";
        $n = M($jpush);
        $j = $n->where(array('id' => $_GET['id']))->delete();
        if ($j > 0 ) {
            $this->success('删除成功!', U('jpush/index'));
        } 
        else {
            $this->error('删除失败，请重试', U('jpush/index'));
        }
    }
}